let users = [];
let listeners = [];


function emitChange(){
  for(let listener of listeners){
    listener()
  }
}

export const userStore = {
  addUser(name) {
    users = [...users, name];
    emitChange();
  },
  subscribe(listener) {
    listeners = [...listeners, listener];
    return () => {
      listeners = listeners.filter((l) => l !== listener);
    };
  },
  getSnapshot(){
    return users
  }
};

